﻿<UserControl
    x:Class="NewsReaderApp.Views.FeedSelector"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:extensions="using:NewsReader.Helpers"
    xmlns:helpers="using:NewsReaderApp.Helpers"
    xmlns:xamltk="using:WinRTXamlToolkit.Controls.Extensions"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <UserControl.Resources>
        <CollectionViewSource x:FieldModifier="Internal" x:Name="feedsByCat" IsSourceGrouped="True"/>
        <helpers:CategoryToColorConverter x:Key="catToColor"/>
    </UserControl.Resources>
    <Grid Margin="20"  Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        <TextBlock  Text="Select Feeds" HorizontalAlignment="Center"  FontSize="25" VerticalAlignment="Center" Style="{StaticResource BasicTextStyle}"/>
        <StackPanel Grid.Row="2" HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal" >
            <Button x:Name="hideSelector"  Visibility="{Binding AnySelected, Converter={StaticResource boolToVis}}" Command="{Binding CancelCommand}"
                Content="Go Back" Grid.Row="2" Style="{StaticResource BasicButton}"/>

            <Button Command="{Binding SaveSelectedFeedsCommand}" x:Name="SelectorCompleted"
                Content="Save and Continue" Grid.Row="2"   Style="{StaticResource BasicButton}"/>
        </StackPanel>

        <GridView x:Name="items" Grid.Row="1"
                    extensions:GridViewBindingHelper.BindableSelection="{Binding SelectedFeeds}"
                    ItemsSource="{Binding Source={StaticResource feedsByCat}}" SelectionMode="Multiple" ItemContainerStyle="{StaticResource CategoryGridViewStyle}" >
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel  Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.ItemTemplate>
                <DataTemplate>
                    <Border Width="200" Height="100" BorderThickness=".5" CornerRadius="3" Background="{Binding Category, Converter={StaticResource catToColor}, ConverterParameter=20}"
                        BorderBrush="{Binding Category, Converter={StaticResource catToColor}}" >
                        <TextBlock Margin="3,20,20,3" TextWrapping="Wrap" HorizontalAlignment="Left" Text="{Binding Title}" FontSize="14"/>
                    </Border>
                </DataTemplate>
            </GridView.ItemTemplate>

            <GridView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Margin="0">
                                <TextBlock Text="{Binding Key}" 
                                           Foreground="{Binding Path=Key, Converter={StaticResource catToColor}}" FontSize="25" Margin="5"/>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>
    </Grid>
</UserControl>
